package com.kele.base.entity;


import com.kele.base.id.SnowflakeGenerator;
import com.kele.base.id.SnowflakeIdSequence;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity<ID extends Serializable> implements Serializable {

    @Serial
    private static final long serialVersionUID =  1L;

    /**
     * 主键
     */
    @Id
    @Schema(description = "主键")
    @Column(name = "\"id\"")
    @SnowflakeIdSequence
    private ID id;

    /**
     * 创建人
     */
    @Schema(description = "创建人")
    @Column(name = "create_user_id")
    @CreatedBy
    private ID createUserId;

    /**
     * 创建时间
     */
    @Schema(description = "创建时间")
    @Column(name = "create_time")
    @CreatedDate
    private LocalDateTime createTime;

    /**
     * 更新人
     */
    @Schema(description = "更新人")
    @Column(name = "update_user_id")
    @LastModifiedBy
    private ID updateUserId;

    /**
     * 更新时间
     */
    @Schema(description = "更新时间")
    @Column(name = "update_time")
    @LastModifiedDate
    private LocalDateTime updateTime;

    public ID getId() {
        return id;
    }

    public void setId(ID id) {
        this.id = id;
    }

    public ID getCreateUserId() {
        return createUserId;
    }

    public void setCreateUserId(ID createUserId) {
        this.createUserId = createUserId;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public ID getUpdateUserId() {
        return updateUserId;
    }

    public void setUpdateUserId(ID updateUserId) {
        this.updateUserId = updateUserId;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public String toString() {
        return "BaseModel{" +
                "id=" + id +
                ", createUserId=" + createUserId +
                ", createTime=" + createTime +
                ", updateUserId=" + updateUserId +
                ", updateTime=" + updateTime +
                '}';
    }
}
